﻿@model IPagedList<Member>
@using EraNet.Core;
@using EraNet.InfoSys;
@using EraNet.InfoSys.Extensions;
@using EraNet.Core.Model.Account;
@using EraNet.InfoSys.Models.Common;
@using EraNet.Core.Model.Test;
@using EraNet.Core.Model.SysManage;
@{
    Layout = "~/Areas/IMS/Views/Shared/_LayOut.cshtml";
    List<CardAllotLogs> cardAllotList = ViewData["cardAllotList"] as List<CardAllotLogs>;
}

@section javascript
{
   
}
<script type="text/javascript">

    
    //获取学习卡
    function GainCads(stuid) {
        $("#card_stuId").val(stuid);
        GetCard();
    }

    function GetCard() {
        $.ajax({
            async: true,
            type: "POST",
            url: "/IMS/Training/GetSingleCardAssigNo",
            dataType: "json",
            success: function (data) {
                if (data != "1") {
                    $("#hid_cardId").val(data.Id);
                    $("#hid_cardPwd").val(data.CardPassword);
                    $("#txt_cardNo").val(data.CardNo);
                }
                else {
                    alert("未获取到可分配的学习卡。");
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert('请求出现异常，请稍后再试'); 
            }
        });

       
    }

    //分配卡片
    function AssigCard() {
       
        var cardNo = $("#txt_cardNo").val();
        var memberId = $("#card_stuId").val();
        var cardId = $("#hid_cardId").val();
        var cardPwd = $("#hid_cardPwd").val();

        var data = "&cardNo=" + cardNo + "&cardPwd=" + cardPwd + "&memberId=" + memberId + "&cardId=" + cardId;
        $.ajax({
            async: false,
            type: "POST",
            url: "/IMS/Training/AssigCard",
            dataType: "json",
            data: data,
            success: function (data) {
                switch (data) {
                    case "1": alert("学习卡号不能为空！"); 
                        break;
                    case "2": alert("该卡已被分配，请重新输入！");
                        break;
                    case "3": alert("分配成功"); location.href="/IMS/Training/StudentList"
                        break;
                    default: alert("分配失败"); 
                        break;
                }

            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert('请求出现异常，请稍后再试'); reloadcode_stu();
            }
        });
    }
</script>
<div class="wrapper">
<!-- Left column/section -->
<div class="column width6 first"  style="display:inline">									
<div class="box box-info" >学员信息列表，您可以通过学员列表页面，操作如学员信息，分配学习卡等操作</div>
<div class="operbox"><input  type="button" value="添加" onclick="javascript:location.href='/IMS/Training/StudentEdit'" /></div>
<table class="display stylized" id="example">
<thead>
<tr>
<th>姓名</th>
<th>用户名</th>
<th>身份证</th>
<th>性别</th>
<th>电话</th>
<th>状态</th>
<th>操作</th>
</tr>
</thead>
<tbody>
@foreach (var m in Model)
{
<tr class="gradeX">
<td><a href="/IMS/Training/StudentInfo?Id=@m.Id"> @Html.Raw(string.IsNullOrEmpty(m.Names) ? m.AccountName : m.Names)</a></td>
<td>@m.AccountName</td>
<td>@m.IDCard</td>
<td>@m.Sex</td>
<td class="center">@m.Telephone</td>
<td class="center">--</td>
<td class="center">
@if (cardAllotList.Where(p => p.MemberId == m.Id).Count()<=0)
{
    <a class="fancybox" href="#divcads" onclick="GainCads(@m.Id)">分配学习卡</a><span style="width:30px"></span>
    <a class="fancybox" href="/IMS/Training/StudentEdit?memberId=@m.Id">修改</a>
}
    </td>
</tr>
}
<tr>
    <td colspan="6" >
    <div id="page">
    <div class="pagecss">
    @{
    var pager = @Html.Pager(new PagerModel()
    {
        PageSize = Model.PageSize,
        TotalRecords = Model.TotalCount,
        PageIndex = Model.PageIndex,
        ShowTotalSummary = false,
        RouteActionName = "IMS_Test",
        UseRouteLinks = true,
        RouteValues = new RouteValues { page = 0 }
    });
}
@pager
    </div>
</div>
</td>
</tr>
</tbody>
</table>				
<div class="clear">&nbsp;</div>
<input id="hid_cardId" type="hidden" />
<input id="hid_cardPwd" type="hidden" />
<input id="card_stuId" type="hidden" />
  <div class="add_student" style="z-index:99999999; display:none" id="divcads">
            <div class="tcaddstudent">
                <div class="addstudentcon_t">
                    <ul class="addconleft">
                        <li><span>学习卡号</span><input type="text" id="txt_cardNo" style="width: 120px;" /><span></span></li>
                    </ul>
                    <div class="clear">
                    </div>
                    <div class="addbuttonb">
                        <input type="button" value="确定" onclick="return AssigCard();" />
                    </div>
                </div>
            </div>
        </div>
		<div id="bodybg">
    </div>
</div>

@Html.Action("_RightNav","Common")
<!-- End of Right column/section -->
</div>
